package com.ruoyi.project.system.approval.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.system.approval.mapper.ApprovalMapper;
import com.ruoyi.project.system.approval.domain.Approval;
import com.ruoyi.project.system.approval.service.IApprovalService;
import com.ruoyi.common.utils.text.Convert;

/**
 * 审批资格Service业务层处理
 * 
 * @author stefan
 * @date 2021-11-10
 */
@Service
public class ApprovalServiceImpl implements IApprovalService 
{
    @Autowired
    private ApprovalMapper approvalMapper;

    /**
     * 查询审批资格
     * 
     * @param id 审批资格主键
     * @return 审批资格
     */
    @Override
    public Approval selectApprovalById(String id)
    {
        return approvalMapper.selectApprovalById(id);
    }

    /**
     * 查询审批资格列表
     * 
     * @param approval 审批资格
     * @return 审批资格
     */
    @Override
    public List<Approval> selectApprovalList(Approval approval)
    {
        return approvalMapper.selectApprovalList(approval);
    }

    /**
     * 新增审批资格
     * 
     * @param approval 审批资格
     * @return 结果
     */
    @Override
    public int insertApproval(Approval approval)
    {
        approval.setCreateTime(DateUtils.getNowDate());
        approval.setUpdateTime(DateUtils.getNowDate());
        String userIdAndNameString  = approval.getUserId();
        String userId = userIdAndNameString.substring(0, userIdAndNameString.indexOf(","));
        String name = userIdAndNameString.substring(userId.length()+1, userIdAndNameString.length());
        approval.setUserId(userId);
        approval.setName(name);
        return approvalMapper.insertApproval(approval);
    }

    /**
     * 修改审批资格
     * 
     * @param approval 审批资格
     * @return 结果
     */
    @Override
    public int updateApproval(Approval approval)
    {
        approval.setUpdateTime(DateUtils.getNowDate());
        return approvalMapper.updateApproval(approval);
    }

    /**
     * 批量删除审批资格
     * 
     * @param ids 需要删除的审批资格主键
     * @return 结果
     */
    @Override
    public int deleteApprovalByIds(String ids)
    {
        return approvalMapper.deleteApprovalByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除审批资格信息
     * 
     * @param id 审批资格主键
     * @return 结果
     */
    @Override
    public int deleteApprovalById(String id)
    {
        return approvalMapper.deleteApprovalById(id);
    }

    /**
     * 查询所有审批领导信息
     * @return
     */
    @Override
    public List<Approval> selectApprovalListAll() {
        return  approvalMapper.selectApprovalListAllMappr();
    }
}
